package com.cz.video.common.storage.dto;

import com.cz.video.common.storage.constants.AliyunConstants;
import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.Data;
import lombok.experimental.Accessors;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Data
@Accessors(chain = true)
public class Statement {
    private String effect;
    private List<String> actions;
    private List<String> resources;

    private Map< String, Object> conditions;

    public Statement(String effect) {
      this.effect = effect;
      actions=new ArrayList<>();
      resources = new ArrayList<>();
      conditions=new HashMap<>();
    }

    public Statement() {
      this(AliyunConstants.ALLOW);
    }


  // 省略构造函数和其他方法

    @JsonProperty("Effect")
    public String getEffect() {
        return effect;
    }

    @JsonProperty("Action")
    public List<String> getActions() {
        return actions;
    }

    @JsonProperty("Resource")
    public List<String> getResources() {
        return resources;
    }

    @JsonProperty("condition")
    public Map<String,Object> getConditions() {
    return conditions;
  }

    /**
     * 添加action
     * @param action
     * @return
     */
    public Statement addAction(String action){
        actions.add(action);
        return this;
      }

    /**
     * 添加resource
     * @param resource
     * @return
     */
    public Statement addResource(String resource){
      resources.add(resource);
      return this;
    }

    /**
     * 添加 condition
     * @return
     */
    public Statement addCondition(String key,Object value){
      conditions.put(key, value);
      return this;
    }
}
